import 'stock_item.dart';

class StockEntry {
  final String id;
  final DateTime date;
  final List<StockItem> items;
  final String supplier;
  final String notes;
  final double totalAmount;

  StockEntry({
    required this.id,
    required this.date,
    required this.items,
    required this.supplier,
    required this.notes,
    required this.totalAmount,
  });

  factory StockEntry.fromJson(Map<String, dynamic> json) {
    return StockEntry(
      id: json['id'] as String,
      date: DateTime.parse(json['date'] as String),
      items: (json['items'] as List)
          .map((item) => StockItem.fromJson(item as Map<String, dynamic>))
          .toList(),
      supplier: json['supplier'] as String,
      notes: json['notes'] as String,
      totalAmount: (json['totalAmount'] as num).toDouble(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'date': date.toIso8601String(),
      'items': items.map((item) => item.toJson()).toList(),
      'supplier': supplier,
      'notes': notes,
      'totalAmount': totalAmount,
    };
  }
} 